package com.mmall.seckill.common;

import lombok.Data;

/**
 * Created by megan on 2018/6/15.
 * 异常管理类
 */
@Data
public class CodeMsg {
    private int code;
    private String msg;

    /** 通用异常 **/
    public static CodeMsg SUCCESS = new CodeMsg(Result.ResultEnumCode.RESULT_SUCCESS.getCode(),Result.ResultEnumCode.RESULT_SUCCESS.getDesc());
    public static CodeMsg ERROR = new CodeMsg(Result.ResultEnumCode.RESULT_ERROR.getCode(),Result.ResultEnumCode.RESULT_ERROR.getDesc());
    //服务端异常
    public static CodeMsg SERVER_ERROR = new CodeMsg(Result.ResultEnumCode.SERVER_ERROR.getCode(), Result.ResultEnumCode.SERVER_ERROR.getDesc());
    //参数校验异常
    public static CodeMsg BIND_ERROR = new CodeMsg(Result.ResultEnumCode.BIND_ERROR.getCode(), Result.ResultEnumCode.BIND_ERROR.getDesc());
    // 访问太频繁
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(Result.ResultEnumCode.ACCESS_LIMIT_REACHED.getCode(), Result.ResultEnumCode.ACCESS_LIMIT_REACHED.getDesc());


    /** 登录模块 5002XX **/
    //Session不存在或者已经失效
    public static CodeMsg SESSION_ERROR = new CodeMsg(Result.ResultEnumCode.SESSION_ERROR.getCode(), Result.ResultEnumCode.SESSION_ERROR.getDesc());
    //登录密码不能为空
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(Result.ResultEnumCode.PASSWORD_EMPTY.getCode(), Result.ResultEnumCode.PASSWORD_EMPTY.getDesc());
    //手机号不能为空
    public static CodeMsg MOBILE_EMPTY = new CodeMsg(Result.ResultEnumCode.MOBILE_EMPTY.getCode(), Result.ResultEnumCode.MOBILE_EMPTY.getDesc());
    //手机号格式错误
    public static CodeMsg MOBILE_ERROR = new CodeMsg(Result.ResultEnumCode.MOBILE_ERROR.getCode(), Result.ResultEnumCode.MOBILE_ERROR.getDesc());
    //手机号不存在
    public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(Result.ResultEnumCode.MOBILE_NOT_EXIST.getCode(), Result.ResultEnumCode.MOBILE_NOT_EXIST.getDesc());
    // 密码错误
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(Result.ResultEnumCode.PASSWORD_ERROR.getCode(), Result.ResultEnumCode.PASSWORD_ERROR.getDesc());


    /** 商品模块 5003XX **/


    /** 订单模块 5004XX **/
    // 没有这个订单
    public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(Result.ResultEnumCode.ORDER_NOT_EXIST.getCode(), Result.ResultEnumCode.ORDER_NOT_EXIST.getDesc());


    /** 秒杀模块 5005XX **/
    //商品已经秒杀完毕
    public static CodeMsg MIAO_SHA_OVER = new CodeMsg(Result.ResultEnumCode.MIAO_SHA_OVER.getCode(), Result.ResultEnumCode.MIAO_SHA_OVER.getDesc());
    //不能重复秒杀
    public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(Result.ResultEnumCode.REPEATE_MIAOSHA.getCode(), Result.ResultEnumCode.REPEATE_MIAOSHA.getDesc());
    //秒杀 排队中
    public static CodeMsg AWAIT_MIAOSHA = new CodeMsg(Result.ResultEnumCode.RESULT_SUCCESS.getCode(), Result.ResultEnumCode.AWAIT_MIAOSHA.getDesc());
    // 秒杀失败
    public static CodeMsg MIAOSHA_FAIL = new CodeMsg(Result.ResultEnumCode.MIAOSHA_FAIL.getCode(), Result.ResultEnumCode.MIAOSHA_FAIL.getDesc());
    // 请求非法
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(Result.ResultEnumCode.REQUEST_ILLEGAL.getCode(), Result.ResultEnumCode.REQUEST_ILLEGAL.getDesc());
    // 验证码失效
    public static CodeMsg VERIFYCODE_FAILURE = new CodeMsg(Result.ResultEnumCode.VERIFYCODE_FAILURE.getCode(), Result.ResultEnumCode.VERIFYCODE_FAILURE.getDesc());
    // 验证码验证失败
    public static CodeMsg VALIDATION_FAILS = new CodeMsg(Result.ResultEnumCode.VALIDATION_FAILS.getCode(), Result.ResultEnumCode.VALIDATION_FAILS.getDesc());

    public CodeMsg fillArgs(Object... args){
        int code = this.code;
        String message = String.format(this.msg,args);
        return new CodeMsg(code,message);
    }

    private CodeMsg(int code, String msg) {
        this.code =code;
        this.msg = msg;
    }
}
